package com.xasxt.book.app.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xasxt.book.app.entity.Book;
import com.xasxt.book.app.entity.User;
import com.xasxt.book.app.service.BookService;
/**
 * 
 * 功能:图书控制器
 * 开发者:虫儿飞
 * 开发时间:2018年5月19日 下午1:50:27
 */
@RestController
public class BookController {

	@Autowired
	private  BookService  bookService;
	/**
	 * 
	 * 功能:添加图书信息
	 * 开发者:虫儿飞
	 * 开发时间:2018年5月26日 下午1:47:36
	 * @param book
	 * @return
	 */
	@RequestMapping("saveBookInfo")
	public int saveBookInfo(Book book) {
		Subject suject=SecurityUtils.getSubject();
		Session session=	suject.getSession();
		User user=(User)session.getAttribute("user");
		if(user!=null) {
			book.setUname(user.getuName());
		}		
		book.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		return bookService.saveBookInfo(book);
	}
	
	
	@RequestMapping("findBookWithPage")
	public Map<String,Object>findBookWithPage(int page,int rows,String bNum,String bName,String author,String publish){
		Map<String,Object>map=new HashMap<String,Object>();
		map.put("page", (page-1)*rows);
		map.put("rows", rows);
		map.put("bName", bName);
		map.put("bNum", bNum);
		map.put("publish",publish);
		map.put("author", author);
		Map<String,Object>result=new HashMap<String,Object>();
		result.put("total", bookService.getCountBook(map));
		result.put("rows", bookService.findBookWithPage(map));
		return result;
	}
	
	

}
